package com.hq.modeapp.ui;

import java.util.ArrayList;

import org.taptwo.android.widget.CircleFlowIndicator;
import org.taptwo.android.widget.MyViewFlow;
import org.taptwo.android.widget.ViewFlow;

import net.tsz.afinal.http.AjaxCallBack;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.v4.view.ViewPager;
import android.text.method.Touch;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;


import com.hq.modeapp.R;
import com.hq.modeapp.adapter.Ad_Image_Adapter;
import com.hq.modeapp.adapter.NewsListViewAdapter;
import com.hq.modeapp.adapter.PhotoListViewAdapter;
import com.hq.modeapp.adapter.VideoListViewAdapter;
import com.hq.modeapp.adapter.myPagerAdapter;
import com.hq.modeapp.bean.Ad_Bean;
import com.hq.modeapp.bean.News_Bean;
import com.hq.modeapp.bean.Photo_List_Bean;
import com.hq.modeapp.bean.Video_Bean;
import com.hq.modeapp.manager.AppContext;
import com.hq.modeapp.manager.AppManager;
import com.hq.modeapp.tools.Tools;
import com.hq.modeapp.tools.YouKuParseURL;
import com.hq.modeapp.widget.PullDownView.OnPullDownListener;
import com.hq.modeapp.widget.PullToRefreshListView;
import com.hq.modeapp.widget.ScrollLayout;
import com.miloisbadboy.view.PullToRefreshView;
import com.miloisbadboy.view.PullToRefreshView.OnFooterRefreshListener;
import com.miloisbadboy.view.PullToRefreshView.OnHeaderRefreshListener;
import com.tgb.lk.demo.dao.impl.News_Bean_DaoImpl;
import com.tgb.lk.demo.dao.impl.Photo_List_Bean_DaoImpl;
import com.tgb.lk.demo.dao.impl.Video_List_Bean_DaoImpl;

public class MainActivity extends BaseActivity implements OnCheckedChangeListener,
		OnPullDownListener, OnClickListener {
	private ImageView mTabImg;// 动画图片
	private RadioGroup rgp_tab;//
	private RadioButton mTab0, mTab1, mTab2, mTab3;
	private int zero = 0;// 动画图片偏移量
	private int currIndex = 0;// 当前页卡编号
	private int one;// 单个水平动画位移
	private int two;
	private int three;
	private ScrollLayout mScrollLayout;
	private long currentTime;
	// tab0
	int startX;// 移动的起始位置
	int avg_width = 0;// 用于记录平均每个标签的宽度，移动的时候需要
	private LayoutInflater inflater;
	private RelativeLayout layout;
	private View page;// 用来存放顶部具体分类的view
	private TextView tv_front;// 需要移动的View
	private TextView tv_bar_news;
	private TextView tv_bar_sport;
	private TextView tv_bar_play;
	private TextView tv_bar_finance;
	private TextView tv_bar_science;
	private TextView tv_bar_more;
	ListView listView;
	String array[] = new String[] { "国内", "军事", "国际", "社会", "深度", "彩票", "电影",
			"音乐", "IT", "汽车", "数码" };
	ViewSwitcher viewswitcher_tab0;
	private PullToRefreshListView pull_down_view_tab0;// 下拉刷新
	private ArrayList<News_Bean> list_tab0_0 = new ArrayList<News_Bean>();
	private NewsListViewAdapter newsListViewAdapter;
	private View lv_footertab0;
	private ProgressBar lv_foot_progresstab0;
	private TextView lv_foot_moretab0;
	private boolean isRefreshingtab0 = false;
	private boolean isFristTab0 = true;
	private News_Bean_DaoImpl news_Bean_Dao = new News_Bean_DaoImpl(
			MainActivity.this);
	private View lv_header;//下拉刷新头部

	
	// tab1
		private PullToRefreshView pull_refresh_view_tab1;
		private ListView lv_tab1;
		private View lv_footer1;
		private ProgressBar lv_foot_progress1;
		private TextView lv_foot_more1;
		private boolean isRefreshing1 = false;
		// private PullDownView mPullDownView;
		// private ListView mListView;
		private VideoListViewAdapter mAdapter1;
		private ArrayList<Video_Bean> list1 = new ArrayList<Video_Bean>();
		private boolean isFristTab1 = true;
		private Video_List_Bean_DaoImpl video_List_Bean_DaoImpl = new Video_List_Bean_DaoImpl(MainActivity.this);
		private Handler handler1 = new Handler();
	
	
	// tab2
	private PullToRefreshView pull_refresh_view_tab2;
	private ListView lv_tab2;
	private View lv_footer;
	private ProgressBar lv_foot_progress;
	private TextView lv_foot_more;
	private boolean isRefreshing = false;
	// private PullDownView mPullDownView;
	// private ListView mListView;
	private PhotoListViewAdapter mAdapter;
	private ArrayList<Photo_List_Bean> list2 = new ArrayList<Photo_List_Bean>();
	private boolean isFristTab2 = true;
	private Photo_List_Bean_DaoImpl photo_List_Bean_DaoImpl = new Photo_List_Bean_DaoImpl(MainActivity.this);
	// tab3
	private ListView listview_tab3;//

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initComponent();
		registerListener();
		System.out.println("时间1====" + System.currentTimeMillis());
		initTab0();//新闻
		initTab1();//视频
		initTab2();//图片
		initTab3();
	}

	private void initTab0() {
		layout = (RelativeLayout) findViewById(R.id.layout_title_bar);
		inflater = getLayoutInflater();

		tv_bar_news = (TextView) findViewById(R.id.tv_title_bar_news);
		tv_bar_sport = (TextView) findViewById(R.id.tv_title_bar_sport);
		tv_bar_play = (TextView) findViewById(R.id.tv_title_bar_play);
		tv_bar_finance = (TextView) findViewById(R.id.tv_title_bar_finance);
		tv_bar_science = (TextView) findViewById(R.id.tv_title_bar_science);
		tv_bar_more = (TextView) findViewById(R.id.tv_title_bar_more);

		tv_bar_news.setOnClickListener(this);
		tv_bar_sport.setOnClickListener(this);
		tv_bar_play.setOnClickListener(this);
		tv_bar_finance.setOnClickListener(this);
		tv_bar_science.setOnClickListener(this);
		tv_bar_more.setOnClickListener(this);

		tv_front = new TextView(this);
		tv_front.setBackgroundResource(R.drawable.slidebar);
		tv_front.setTextColor(Color.WHITE);
		tv_front.setText("头条");
		tv_front.setGravity(Gravity.CENTER);
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		param.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		layout.addView(tv_front, param);

		pull_down_view_tab0 = (PullToRefreshListView) findViewById(R.id.pull_down_view_tab0);
		lv_footertab0 = getLayoutInflater().inflate(R.layout.listview_footer,
				null);
		lv_foot_moretab0 = (TextView) lv_footertab0
				.findViewById(R.id.listview_foot_more);
		lv_foot_progresstab0 = (ProgressBar) lv_footertab0
				.findViewById(R.id.listview_foot_progress);
		pull_down_view_tab0.addFooterView(lv_footertab0);// 添加底部视图
		lv_header
		 =getLayoutInflater().inflate(R.layout.head_advertisment, null);
		 lv_header.findViewById(R.id.viewflow_tab0).setLayoutParams(new LayoutParams(Tools.getInstance().getScreenWidth(this), Tools.getInstance().dipTopx(this, 180)));
		 System.out.println("screenWidth====="+Tools.getInstance().getScreenWidth(this));
		 mScrollLayout.setWidthAndHeight(Tools.getInstance().getScreenWidth(this), Tools.getInstance().dipTopx(this, 180));
		 pull_down_view_tab0.addHeaderView(lv_header);	
		// 必须在setAdapter前
		//添加viewFlow时要注意：计算viewFlow的高度和宽，要不抛出异常
		
		mAdapter = new PhotoListViewAdapter(this, list2);
		newsListViewAdapter = new NewsListViewAdapter(this, list_tab0_0);
		pull_down_view_tab0.setAdapter(newsListViewAdapter);
		pull_down_view_tab0
				.setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() {
					public void onRefresh() {
						if (!isRefreshingtab0) {
							initRefreshingComponent_tab0();
							ArrayList<News_Bean> list = news_Bean_Dao.findAll();
							System.out.println("list===" + list.size());
							if (list.size() > 0) {
								list_tab0_0.clear();
								list_tab0_0.addAll(list);
								newsListViewAdapter.setList(list);
								mAdapter.notifyDataSetChanged();
							}
							new Thread(new Runnable() {

								@Override
								public void run() {
									String URL2 = "http://c.3g.163.com/nc/article/headline/T1347415223240/0-20.html";
									((AppContext) getApplicationContext()).finalHttp
											.get(URL2,
													new AjaxCallBack<String>() {

														@Override
														public void onSuccess(
																String t) {
															super.onSuccess(t);
															final String result = t;
															final Handler  handler = new Handler();
															new Thread(new Runnable() {
																
																@Override
																public void run() {
																	// TODO Auto-generated method stub
																	System.out.println("网易新闻图片列表==" + result.toString());
																	list_tab0_0.clear();
																	list_tab0_0.addAll(News_Bean.parseJson(result));
																	newsListViewAdapter.setList(list_tab0_0);
																	news_Bean_Dao.deleteAll();
																	news_Bean_Dao.insertList(list_tab0_0);
																	System.out.println("list2.size()=" + list2.size());
																	handler.post(new Runnable() {
																		
																		@Override
																		public void run() {
																			mAdapter.notifyDataSetChanged();
																			// 诉它数据加载完毕;
																			// mPullDownView.notifyDidLoad();
																			initRefreshedComponent_tab0();
																		}
																	});
																}
															}).start();
															
															
														}

														@Override
														public void onFailure(
																Throwable t,
																String strMsg) {
															// TODO
															// Auto-generated
															// method stub
															super.onFailure(t,
																	strMsg);
															System.out
																	.println("网易新闻图片列表"
																			+ strMsg);
															Tools.getInstance()
																	.showTextToast(
																			MainActivity.this,
																			"网络异常！");
															// 诉它数据加载完毕;
															// mPullDownView.notifyDidLoad();
															initRefreshedComponent_tab0();
														}
													});
								}
							}).start();

						} else {
							pull_down_view_tab0.onRefreshComplete();
						}

					}
				});

		
		
		pull_down_view_tab0.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				System.out.println("postion===="+position);
				// 点击头部、底部栏无效
				if (position == 0 || view == lv_footer)
					return;
				
				
				System.out.println("=======position========"+position);
				Intent intent = new Intent(MainActivity.this,WebView_Activity.class);
				News_Bean bean = list_tab0_0.get(position-2);
				Bundle bundle = new Bundle();
		        bundle.putSerializable("bean", bean);
		        intent.putExtras(bundle);
		        startActivity(intent);
				
				
				// News news = null;
				// //判断是否是TextView
				// if(view instanceof TextView){
				// news = (News)view.getTag();
				// }else{
				// TextView tv =
				// (TextView)view.findViewById(R.id.news_listitem_title);
				// news = (News)tv.getTag();
				// }
				// if(news == null) return;
				//
				// //跳转到新闻详情
				// UIHelper.showNewsRedirect(view.getContext(), news);
			}
		});
		
		
		lv_footertab0.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (!isRefreshingtab0) {
					initRefreshingComponent_tab0();
					String url = null;
					if (list_tab0_0.size() == 0) {
						url = "http://c.3g.163.com/nc/article/headline/T1347415223240/0-20.html";
					} else {
						url = "http://c.3g.163.com/nc/article/headline/T1347415223240/"
								+ list_tab0_0.size() + "-20.html";
					}
					((AppContext) getApplicationContext()).finalHttp.get(url,
							new AjaxCallBack<String>() {

								@Override
								public void onSuccess(String t) {
									// TODO
									// Auto-generated
									// method stub
									super.onSuccess(t);
									System.out.println("网易新闻图片列表=="
											+ t.toString());
									list_tab0_0.addAll(News_Bean.parseJson(t));
									newsListViewAdapter.setList(list_tab0_0);
									System.out.println("list2.size()="
											+ list_tab0_0.size());
									mAdapter.notifyDataSetChanged();
									// 诉它数据加载完毕;
									// mPullDownView.notifyDidLoad();
									initRefreshedComponent_tab0();
								}

								@Override
								public void onFailure(Throwable t, String strMsg) {
									// TODO
									// Auto-generated
									// method stub
									super.onFailure(t, strMsg);
									System.out.println("网易新闻图片列表" + strMsg);
									Tools.getInstance().showTextToast(
											MainActivity.this, "网络异常！");
									// 诉它数据加载完毕;
									// mPullDownView.notifyDidLoad();
									initRefreshedComponent_tab0();
								}
							});

				}
			}
		});

		viewswitcher_tab0 = (ViewSwitcher) findViewById(R.id.viewswitcher_tab0);
		listView = (ListView) findViewById(R.id.listView_news_more);
		listView.setAdapter(new BaseAdapter() {

			@Override
			public int getCount() {
				return array.length;
			}

			@Override
			public Object getItem(int position) {
				return null;
			}

			@Override
			public long getItemId(int position) {
				return 0;
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				ViewHolder holder;
				if (convertView == null) {
					convertView = getLayoutInflater().inflate(
							R.layout.layout_news_more_item, null);
					holder = new ViewHolder();
					holder.tv = (TextView) convertView
							.findViewById(R.id.tv_news_more_item);
					convertView.setTag(holder);
				} else {
					holder = (ViewHolder) convertView.getTag();
				}
				holder.tv.setText(array[position]);
				return convertView;
			}

			class ViewHolder {
				TextView tv;
			}

		});

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// Intent intent = new Intent(TabNewsMoreActivity.this,
				// NewsMoreContentActivity.class);
				// Bundle bundle = new Bundle();
				switch (position) {
				case 0:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_DOMESTIC);
					break;
				case 1:
					Tools.getInstance().showTextToast(MainActivity.this, "1");
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_MILITARY);
					break;
				case 2:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_INTERNATIONAL);
					break;
				case 3:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_COMMUNITY);
					break;
				case 4:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_DEPTH);
					break;
				case 5:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_TICKET);
					break;
				case 6:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_FILM);
					break;
				case 7:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_MUSIC);
					break;
				case 8:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_IT);
					break;
				case 9:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_CAR);
					break;
				case 10:
					// bundle.putString("more_news_list_url",
					// CONST.URL_NEWS_DIGITAL);
					break;
				}

				// bundle.putString("text", array[position]);
				// intent.putExtras(bundle);
				// TabNewsMoreActivity.this.startActivity(intent);

			}
		});

		initRefreshingComponent_tab0();
		ArrayList<News_Bean> list = news_Bean_Dao.findAll();
		System.out.println("list===" + list.size());
		if (list.size() > 0) {
			list_tab0_0.clear();
			list_tab0_0.addAll(list);
			newsListViewAdapter.setList(list);
			mAdapter.notifyDataSetChanged();
		}
		String URL2 = "http://c.3g.163.com/nc/article/headline/T1347415223240/0-20.html";
		((AppContext) getApplicationContext()).finalHttp.get(URL2,
				new AjaxCallBack<String>() {
				
					@Override
					public void onSuccess(String t) {
						super.onSuccess(t);
						final String result = t;
						final Handler  handler = new Handler();
						new Thread(new Runnable() {
							
							@Override
							public void run() {
								// TODO Auto-generated method stub
								System.out.println("网易新闻图片列表==" + result.toString());
								list_tab0_0.clear();
								list_tab0_0.addAll(News_Bean.parseJson(result));
								newsListViewAdapter.setList(list_tab0_0);
								news_Bean_Dao.deleteAll();
								news_Bean_Dao.insertList(list_tab0_0);
								System.out.println("list2.size()=" + list2.size());
								handler.post(new Runnable() {
									
									@Override
									public void run() {
										mAdapter.notifyDataSetChanged();
										// 诉它数据加载完毕;
										// mPullDownView.notifyDidLoad();
										initRefreshedComponent_tab0();
									}
								});
							}
						}).start();
						
						
					}

					@Override
					public void onFailure(Throwable t, String strMsg) {
						// TODO
						// Auto-generated
						// method stub
						super.onFailure(t, strMsg);
						System.out.println("网易新闻图片列表" + strMsg);
						Tools.getInstance().showTextToast(MainActivity.this,
								"网络异常！");
						// 诉它数据加载完毕;
						// mPullDownView.notifyDidLoad();
						initRefreshedComponent_tab0();
					}
				});

		
		
		String URL3 = "http://c.3g.163.com//nc/ad/headline/android/0-3.html";
		((AppContext) getApplicationContext()).finalHttp.get(URL3,
				new AjaxCallBack<String>() {

					@Override
					public void onSuccess(String t) {
						// TODO
						// Auto-generated
						// method stub
						super.onSuccess(t);
						System.out.println("网易ad新闻图片列表==" + t.toString());
						ArrayList<Ad_Bean> list = Ad_Bean.parseJson(t);
						initPanel(list);
					}

					@Override
					public void onFailure(Throwable t, String strMsg) {
						// TODO
						// Auto-generated
						// method stub
						super.onFailure(t, strMsg);
						System.out.println("网易ad新闻图片列表" + strMsg);
						Tools.getInstance().showTextToast(MainActivity.this,
								"网络异常！");
						// 诉它数据加载完毕;
						// mPullDownView.notifyDidLoad();
					}
				});
		
		System.out.println("时间6====" + System.currentTimeMillis());

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {

			Intent intent = new Intent();
        	intent.setClass(this,Exit_Dialog_Activity.class);
        	startActivity(intent);
			
//			long temp = System.currentTimeMillis();
//			if ((temp - currentTime) < 2000) {
//				AppManager.getAppManager().AppExit(this);
//			} else {
//				currentTime = temp;
//				Toast.makeText(this, "再按一次回退，退出程序", Toast.LENGTH_SHORT).show();
//				return false;
//			}
		}
		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 
	 * @函数名称 : initTab3
	 * @功能描述 :
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-5-15 下午1:54:52 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initTab3() {
		listview_tab3 = (ListView) findViewById(R.id.listview_tab3);
		listview_tab3.setAdapter(new BaseAdapter() {

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return 1;
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				View view = getLayoutInflater().inflate(
						R.layout.main_system_set, null);
				return view;
			}

			@Override
			public long getItemId(int position) {
				// TODO Auto-generated method stub
				return 0;
			}

			@Override
			public Object getItem(int position) {
				// TODO Auto-generated method stub
				return null;
			}

		});
		// pull_listview_tab3.addView();
	}

	
	
	/**
	 * 
	 * @函数名称 : initTab1
	 * @功能描述 : 初始化tab1界面的控件与监听
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-5-13 下午12:05:47 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initTab1() {
		lv_footer1 = getLayoutInflater().inflate(R.layout.listview_footer, null);
		lv_foot_more1 = (TextView) lv_footer1
				.findViewById(R.id.listview_foot_more);
		lv_foot_progress1 = (ProgressBar) lv_footer1
				.findViewById(R.id.listview_foot_progress);
		pull_refresh_view_tab1 = (PullToRefreshView) findViewById(R.id.pull_refresh_view_tab1);
		lv_tab1 = (ListView) pull_refresh_view_tab1.findViewById(android.R.id.list);
		mAdapter1 = new VideoListViewAdapter(this, list1);
		lv_tab1.setAdapter(mAdapter1);
		pull_refresh_view_tab1.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				// TODO Auto-generated method stub

				if (!isRefreshing1) {
					initRefreshingComponent_tab1();
					ArrayList<Video_Bean> list = new Video_List_Bean_DaoImpl(
							MainActivity.this).findAll();
					System.out.println("list===" + list.size());
					if (list.size() > 0) {
						list1.clear();
						list1.addAll(list);
						mAdapter1.setList(list1);
						mAdapter1.notifyDataSetChanged();
					}
					new Thread(new Runnable() {
						ArrayList<Video_Bean>  list_temp  = new ArrayList<Video_Bean>();
						boolean isFlag = true;
						@Override
						public void run() {
							try {
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNTE2NzcxOTQ0.html"));//我只在乎你
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNTA3MDA3MjMy.html"));//千千阙歌-陈慧琳
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDg0OTQxNTEy.html"));//追
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDc3MjY1ODYw.html"));//明星
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDYwMTI2NzMy.html"));//似水流年
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XMzczMzMyMzg0.html"));//monica
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XMzc0MzgwODky.html"));//风继续吹
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDE0MDExMjIw.html"));//红颜白发
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDA4NDgxODE2.html"));//路过蜻蜓
								list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDQ0MzAxMTUy.html"));//我的心里只有你没有他
							} catch (Exception e) {
								isFlag = false;
								e.printStackTrace();
							}
							if(isFlag){
								list1.clear();
								list1.addAll(list_temp);
								mAdapter1.setList(list1);
								video_List_Bean_DaoImpl
										.deleteAll();
								long time = System.currentTimeMillis();
								video_List_Bean_DaoImpl
										.insertList(list1);
								System.out.println("list1.size()="
										+ list1.size());
							}
							
							handler1.post(new Runnable() {
								
								@Override
								public void run() {
									
									mAdapter1.notifyDataSetChanged();
										// 诉它数据加载完毕;
										// mPullDownView.notifyDidLoad();
										initRefreshedComponent_tab1();
									
									
								}
							});
							
						}
					}).start();

				} else {
					//设置更新时间
					//mPullToRefreshView.onHeaderRefreshComplete("最近更新:01-23 12:01");
					pull_refresh_view_tab1.onHeaderRefreshComplete();
				}
			}
		});
		
		pull_refresh_view_tab1.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				// TODO Auto-generated method stub
				pull_refresh_view_tab1.onFooterRefreshComplete();
				initRefreshedComponent_tab1();
				
//				if (!isRefreshing1) {
//					initRefreshingComponent_tab1();
//					String url = null;
//					if (list2.size() == 0) {
//						url = "http://c.3g.163.com/photo/api/list/0096/4GJ60096.json";
//					} else {
//						Photo_List_Bean bean = list2.get(list2.size() - 1);
//						String id = bean.getSetid();
//						url = "http://c.3g.163.com/photo/api/morelist/0096/4GJ60096/"
//								+ id + ".json";
//					}
//					((AppContext) getApplicationContext()).finalHttp.get(url,
//							new AjaxCallBack<String>() {
//
//								@Override
//								public void onSuccess(String t) {
//									// TODO
//									// Auto-generated
//									// method stub
//									super.onSuccess(t);
//									System.out.println("网易新闻图片列表=="
//											+ t.toString());
//									list2.addAll(Photo_List_Bean.parseJson(t));
//									mAdapter.setList(list2);
//									System.out.println("list2.size()="
//											+ list2.size());
//									mAdapter.notifyDataSetChanged();
//									// 诉它数据加载完毕;
//									// mPullDownView.notifyDidLoad();
//									initRefreshedComponent_tab2();
//								}
//
//								@Override
//								public void onFailure(Throwable t, String strMsg) {
//									// TODO
//									// Auto-generated
//									// method stub
//									super.onFailure(t, strMsg);
//									System.out.println("网易新闻图片列表" + strMsg);
//									Tools.getInstance().showTextToast(
//											MainActivity.this, "网络异常！");
//									// 诉它数据加载完毕;
//									// mPullDownView.notifyDidLoad();
//									initRefreshedComponent_tab2();
//								}
//							});
//
//				}
			
			}
		});
		


	}
	
	/**
	 * 
	 * @函数名称 : initTab2
	 * @功能描述 : 初始化tab2界面的控件与监听
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-5-13 下午12:05:47 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initTab2() {
		lv_footer = getLayoutInflater().inflate(R.layout.listview_footer, null);
		lv_foot_more = (TextView) lv_footer
				.findViewById(R.id.listview_foot_more);
		lv_foot_progress = (ProgressBar) lv_footer
				.findViewById(R.id.listview_foot_progress);
		pull_refresh_view_tab2 = (PullToRefreshView) findViewById(R.id.pull_refresh_view_tab2);
		lv_tab2 = (ListView) pull_refresh_view_tab2.findViewById(android.R.id.list);
		mAdapter = new PhotoListViewAdapter(this, list2);
		lv_tab2.setAdapter(mAdapter);
		pull_refresh_view_tab2.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				// TODO Auto-generated method stub

				if (!isRefreshing) {
					initRefreshingComponent_tab2();
					ArrayList<Photo_List_Bean> list = new Photo_List_Bean_DaoImpl(
							MainActivity.this).findAll();
					System.out.println("list===" + list.size());
					if (list.size() > 0) {
						list2.clear();
						list2.addAll(list);
						mAdapter.setList(list);
						mAdapter.notifyDataSetChanged();
					}
					new Thread(new Runnable() {

						@Override
						public void run() {
							String URL2 = "http://c.3g.163.com/photo/api/list/0096/4GJ60096.json";
							((AppContext) getApplicationContext()).finalHttp
									.get(URL2, new AjaxCallBack<String>() {

										@Override
										public void onSuccess(String t) {
											super.onSuccess(t);
											final String result = t;
											final Handler handler = new Handler();
											new Thread(new Runnable() {
												
												@Override
												public void run() {
													// TODO Auto-generated method stub
													System.out.println("网易新闻图片列表=="
															+ result);
													list2.clear();
													list2.addAll(Photo_List_Bean
															.parseJson(result));
													mAdapter.setList(list2);
													photo_List_Bean_DaoImpl
															.deleteAll();
													long time = System.currentTimeMillis();
													photo_List_Bean_DaoImpl
															.insertList(list2);
													System.out.println("time2==="+(System.currentTimeMillis()-time));
													System.out.println("list2.size()="
															+ list2.size());
													handler.post(new Runnable() {
														
														@Override
														public void run() {
															// TODO Auto-generated method stub
															mAdapter.notifyDataSetChanged();
															// 诉它数据加载完毕;
															// mPullDownView.notifyDidLoad();
															initRefreshedComponent_tab2();
														}
													});
													
													
												}
											}).start();
											
										}

										@Override
										public void onFailure(Throwable t,
												String strMsg) {
											// TODO
											// Auto-generated
											// method stub
											super.onFailure(t, strMsg);
											System.out.println("网易新闻图片列表"
													+ strMsg);
											Tools.getInstance().showTextToast(
													MainActivity.this, "网络异常！");
											// 诉它数据加载完毕;
											// mPullDownView.notifyDidLoad();
											initRefreshedComponent_tab2();
										}
									});
						}
					}).start();

				} else {
					//设置更新时间
					//mPullToRefreshView.onHeaderRefreshComplete("最近更新:01-23 12:01");
					pull_refresh_view_tab2.onHeaderRefreshComplete();
				}
			}
		});
		
		pull_refresh_view_tab2.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				// TODO Auto-generated method stub

				if (!isRefreshing) {
					initRefreshingComponent_tab2();
					String url = null;
					if (list2.size() == 0) {
						url = "http://c.3g.163.com/photo/api/list/0096/4GJ60096.json";
					} else {
						Photo_List_Bean bean = list2.get(list2.size() - 1);
						String id = bean.getSetid();
						url = "http://c.3g.163.com/photo/api/morelist/0096/4GJ60096/"
								+ id + ".json";
					}
					((AppContext) getApplicationContext()).finalHttp.get(url,
							new AjaxCallBack<String>() {

								@Override
								public void onSuccess(String t) {
									// TODO
									// Auto-generated
									// method stub
									super.onSuccess(t);
									System.out.println("网易新闻图片列表=="
											+ t.toString());
									list2.addAll(Photo_List_Bean.parseJson(t));
									mAdapter.setList(list2);
									System.out.println("list2.size()="
											+ list2.size());
									mAdapter.notifyDataSetChanged();
									// 诉它数据加载完毕;
									// mPullDownView.notifyDidLoad();
									initRefreshedComponent_tab2();
								}

								@Override
								public void onFailure(Throwable t, String strMsg) {
									// TODO
									// Auto-generated
									// method stub
									super.onFailure(t, strMsg);
									System.out.println("网易新闻图片列表" + strMsg);
									Tools.getInstance().showTextToast(
											MainActivity.this, "网络异常！");
									// 诉它数据加载完毕;
									// mPullDownView.notifyDidLoad();
									initRefreshedComponent_tab2();
								}
							});

				}
			
			}
		});
		


	}

	@Override
	protected void onResume() {
		super.onResume();
		// 水平滑动是否开启
		mScrollLayout.setIsScroll(true);
	}
	
	
	/**
	 * 
	 * @函数名称 : initPanel
	 * @功能描述 :
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-26 下午1:41:03 修改人：黄秋
	 * @描述 ：初始化广告控件
	 * 
	 */
	private void initPanel(ArrayList<Ad_Bean> list) {
//		if (list.isEmpty()) {
//			Ad_Bean adBean = new Ad_Bean();
//			adBean.setTitle("");
//			adBean.setImgsrc("");
//			list.add(0, adBean);// 添加本地广告
//		}
		// 当viewFlow中设置了setSelection()或者在进行切换到另一个画面是会进行监听，调用setOnViewSwitchListener监听方法
		// viewflow.setOnViewSwitchListener(new ViewSwitchListener() {
		//
		// @Override
		// public void onSwitched(View view, int position) {
		// // TODO Auto-generated method stub
		// currentIndex = position;
		// System.out.println("view位置===" + position);
		// }
		// });
		ViewFlow viewflow = (ViewFlow) lv_header.findViewById(R.id.viewflow_tab0);
		viewflow.setAdapter(new Ad_Image_Adapter(this, list,(TextView)(lv_header.findViewById(R.id.tv_title))));
		viewflow.setmSideBuffer(list.size()); // 实际图片张数， 我的ImageAdapter实际图片张数为3
		CircleFlowIndicator indic = (CircleFlowIndicator) (lv_header.findViewById(R.id.headline_indicator));
		viewflow.setFlowIndicator(indic);
		viewflow.setTimeSpan(4500);
		viewflow.setSelection(3 * 1000); // 设置初始位置
		viewflow.startAutoFlowTimer(); // 启动自动播放
	}
	
	
	
//	private void initPanel2(ArrayList<Ad_Bean> list) {
////		if (list.isEmpty()) {
//			Ad_Bean adBean = new Ad_Bean();
//			adBean.setTitle("");
//			adBean.setImgsrc("");
//			list.add(0, adBean);// 添加本地广告
////		}
//		// 当viewFlow中设置了setSelection()或者在进行切换到另一个画面是会进行监听，调用setOnViewSwitchListener监听方法
//		// viewflow.setOnViewSwitchListener(new ViewSwitchListener() {
//		//
//		// @Override
//		// public void onSwitched(View view, int position) {
//		// // TODO Auto-generated method stub
//		// currentIndex = position;
//		// System.out.println("view位置===" + position);
//		// }
//		// });
//		ViewPager viewflow = (ViewPager) lv_header.findViewById(R.id.viewflow_tab0);
//		ImageView imageView = new ImageView(this);
//		imageView.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT));
//		imageView.setImageResource(R.drawable.guide_pic3);
//		ImageView imageView2 = new ImageView(this);
//		imageView2.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT));
//		imageView2.setImageResource(R.drawable.guide_pic3);
//		ArrayList<View> list2 = new ArrayList<View>();
//		list2.add(imageView);
//		list2.add(imageView2);
//		viewflow.setAdapter(new myPagerAdapter(list2));
////		viewflow.setAdapter(new Ad_Image_Adapter(this, list,(TextView)(lv_header.findViewById(R.id.tv_title))));
////		viewflow.setmSideBuffer(list.size()); // 实际图片张数， 我的ImageAdapter实际图片张数为3
////		CircleFlowIndicator indic = (CircleFlowIndicator) (lv_header.findViewById(R.id.headline_indicator));
////		viewflow.setFlowIndicator(indic);
////		viewflow.setTimeSpan(4500);
////		viewflow.setSelection(3 * 1000); // 设置初始位置
////		viewflow.startAutoFlowTimer(); // 启动自动播放
//	}
	
	
	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新中的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshingComponent_tab1() {
		isRefreshing1 = true;// 下拉刷新不可用
		lv_foot_more1.setText("加载中···");
		if (lv_foot_progress1 != null
				&& lv_foot_progress1.getVisibility() == View.GONE) {
			lv_foot_progress1.setVisibility(View.VISIBLE);
		}

	}
	
	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新完成后的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshedComponent_tab1() {
		isRefreshing1 = false;// 下拉刷新不可用
		lv_foot_more1.setText("更多");
		if (lv_foot_progress1 != null
				&& lv_foot_progress1.getVisibility() == View.VISIBLE) {
			lv_foot_progress1.setVisibility(View.GONE);
		}
		if (lv_tab1 != null) {
			pull_refresh_view_tab1.onHeaderRefreshComplete();
			pull_refresh_view_tab1.onFooterRefreshComplete();
		}
	}
	
	
	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新中的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshingComponent_tab2() {
		isRefreshing = true;// 下拉刷新不可用
		lv_foot_more.setText("加载中···");
		if (lv_foot_progress != null
				&& lv_foot_progress.getVisibility() == View.GONE) {
			lv_foot_progress.setVisibility(View.VISIBLE);
		}

	}

	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新完成后的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshedComponent_tab2() {
		isRefreshing = false;// 下拉刷新不可用
		lv_foot_more.setText("更多");
		if (lv_foot_progress != null
				&& lv_foot_progress.getVisibility() == View.VISIBLE) {
			lv_foot_progress.setVisibility(View.GONE);
		}
		if (lv_tab2 != null) {
			pull_refresh_view_tab2.onHeaderRefreshComplete();
			pull_refresh_view_tab2.onFooterRefreshComplete();
		}
	}

	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新中的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshingComponent_tab0() {
		isRefreshingtab0 = true;// 下拉刷新不可用
		lv_foot_moretab0.setText("加载中···");
		if (lv_foot_progresstab0 != null
				&& lv_foot_progresstab0.getVisibility() == View.GONE) {
			lv_foot_progresstab0.setVisibility(View.VISIBLE);
		}

	}

	/**
	 * 
	 * @函数名称 : initRefreshingComponent
	 * @功能描述 : 初始化正在刷新完成后的控件
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-3-21 下午3:44:50 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public void initRefreshedComponent_tab0() {
		isRefreshingtab0 = false;// 下拉刷新不可用
		lv_foot_moretab0.setText("更多");
		if (lv_foot_progresstab0 != null
				&& lv_foot_progresstab0.getVisibility() == View.VISIBLE) {
			lv_foot_progresstab0.setVisibility(View.GONE);
		}
		if (pull_down_view_tab0 != null) {
			pull_down_view_tab0.onRefreshComplete();
		}
	}

	/**
	 * 
	 * @函数名称 : initComponent
	 * @功能描述 :
	 * @参数及返回值说明：
	 * 
	 * @修改记录：
	 * @日期：2013-5-3 下午2:01:57 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	private void initComponent() {
		// 启动activity时不自动弹出软键盘
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		mScrollLayout = (ScrollLayout) findViewById(R.id.main_scrolllayout);
		rgp_tab = (RadioGroup) findViewById(R.id.rgp_tab);
		mTabImg = (ImageView) findViewById(R.id.img_tab_now);
		mTab0 = (RadioButton) findViewById(R.id.img_weixin);
		mTab1 = (RadioButton) findViewById(R.id.img_address);
		mTab2 = (RadioButton) findViewById(R.id.img_friends);
		mTab3 = (RadioButton) findViewById(R.id.img_settings);
		Display currDisplay = getWindowManager().getDefaultDisplay();// ��ȡ��Ļ��ǰ�ֱ���
		int displayWidth = currDisplay.getWidth();
		int displayHeight = currDisplay.getHeight();
		one = displayWidth / 4; // ����ˮƽ����ƽ�ƴ�С
		two = one * 2;
		three = one * 3;
		mTab0.setChecked(true);
	}

	/**
	 * @������� : registerListener
	 * @�������� :
	 * @�����ֵ˵��
	 * 
	 * @�޸ļ�¼��
	 * @���ڣ�2012-12-14 ����1:19:49 �޸��ˣ�Administrator
	 * @���� ��
	 * 
	 */
	private void registerListener() {
		rgp_tab.setOnCheckedChangeListener(this);
		mScrollLayout
				.SetOnViewChangeListener(new ScrollLayout.OnViewChangeListener() {
					public void OnViewChange(int viewIndex) {
						// �л��б���ͼ-����б����Ϊ�գ��������
						switch (viewIndex) {
						case 0:// ��Ѷ
							rgp_tab.check(mTab0.getId());

							break;
						case 1:// �ʴ�
							rgp_tab.check(mTab1.getId());
							
							if (isFristTab1) {
								isFristTab1 = false;
								if (!isRefreshing1) {
									initRefreshingComponent_tab1();
									ArrayList<Video_Bean> list = new Video_List_Bean_DaoImpl(
											MainActivity.this).findAll();
									System.out.println("list===" + list.size());
									if (list.size() > 0) {
										list1.clear();
										list1.addAll(list);
										mAdapter1.setList(list1);
										mAdapter1.notifyDataSetChanged();
									}
									new Thread(new Runnable() {
										ArrayList<Video_Bean>  list_temp  = new ArrayList<Video_Bean>();
										boolean isFlag = true;
										@Override
										public void run() {
											try {
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNTE2NzcxOTQ0.html"));//我只在乎你
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNTA3MDA3MjMy.html"));//千千阙歌-陈慧琳
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDg0OTQxNTEy.html"));//追
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDc3MjY1ODYw.html"));//明星
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDYwMTI2NzMy.html"));//似水流年
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XMzczMzMyMzg0.html"));//monica
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XMzc0MzgwODky.html"));//风继续吹
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDE0MDExMjIw.html"));//红颜白发
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDA4NDgxODE2.html"));//路过蜻蜓
												list_temp.add(YouKuParseURL.videoParseURL("http://v.youku.com/v_show/id_XNDQ0MzAxMTUy.html"));//我的心里只有你没有他
											} catch (Exception e) {
												isFlag = false;
												e.printStackTrace();
											}
											if(isFlag){
												list1.clear();
												list1.addAll(list_temp);
												mAdapter1.setList(list1);
												video_List_Bean_DaoImpl
														.deleteAll();
												long time = System.currentTimeMillis();
												video_List_Bean_DaoImpl
														.insertList(list1);
												System.out.println("list1.size()="
														+ list1.size());
											}
											
											handler1.post(new Runnable() {
												
												@Override
												public void run() {
													
														mAdapter1.notifyDataSetChanged();
														// 诉它数据加载完毕;
														// mPullDownView.notifyDidLoad();
														initRefreshedComponent_tab1();
													
													
												}
											});
											
										}
									}).start();

								} else {
									//设置更新时间
									//mPullToRefreshView.onHeaderRefreshComplete("最近更新:01-23 12:01");
									pull_refresh_view_tab1.onHeaderRefreshComplete();
								}
							}
							
							
							break;
						case 2:// 朋友们---网易图片
							rgp_tab.check(mTab2.getId());
							if (isFristTab2) {
								isFristTab2 = false;
								if (!isRefreshing) {
									initRefreshingComponent_tab2();
									ArrayList<Photo_List_Bean> list = new Photo_List_Bean_DaoImpl(
											MainActivity.this).findAll();
									System.out.println("list===" + list.size());
									if (list.size() > 0) {
										mAdapter.setList(list);
										mAdapter.notifyDataSetChanged();
									}
									String URL2 = "http://c.3g.163.com/photo/api/list/0096/4GJ60096.json";
									((AppContext) getApplicationContext()).finalHttp
											.get(URL2,
													new AjaxCallBack<String>() {

														@Override
														public void onSuccess(
																String t) {
															super.onSuccess(t);
															final String result = t;
															final Handler handler = new Handler();
															new Thread(new Runnable() {
																
																@Override
																public void run() {
																	// TODO Auto-generated method stub
																	System.out.println("网易新闻图片列表=="
																			+ result);
																	list2.clear();
																	list2.addAll(Photo_List_Bean
																			.parseJson(result));
																	mAdapter.setList(list2);
																	photo_List_Bean_DaoImpl
																			.deleteAll();
																	long time = System.currentTimeMillis();
																	photo_List_Bean_DaoImpl
																			.insertList(list2);
																	System.out.println("time2==="+(System.currentTimeMillis()-time));
																	System.out.println("list2.size()="
																			+ list2.size());
																	handler.post(new Runnable() {
																		
																		@Override
																		public void run() {
																			// TODO Auto-generated method stub
																			mAdapter.notifyDataSetChanged();
																			// 诉它数据加载完毕;
																			// mPullDownView.notifyDidLoad();
																			initRefreshedComponent_tab2();
																		}
																	});
																	
																	
																}
															}).start();
															
														}

														@Override
														public void onFailure(
																Throwable t,
																String strMsg) {
															// TODO
															// Auto-generated
															// method
															// stub
															super.onFailure(t,
																	strMsg);
															System.out
																	.println("网易新闻图片列表"
																			+ strMsg);
															Tools.getInstance()
																	.showTextToast(
																			MainActivity.this,
																			"网络异常！");
															// 诉它数据加载完毕;
															// mPullDownView.notifyDidLoad();
															initRefreshedComponent_tab2();
														}
													});
								}
							}
							break;
						case 3:// ��̬
							rgp_tab.check(mTab3.getId());
							break;
						}
					}
				});
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {

		if (mTab0.getId() == checkedId) {
			if (currIndex == 1) {
				moveFrontBg(mTabImg, one, 0, 0, 0);
			} else if (currIndex == 2) {
				moveFrontBg(mTabImg, two, 0, 0, 0);
			} else if (currIndex == 3) {
				moveFrontBg(mTabImg, three, 0, 0, 0);
			}
			currIndex = 0;
			mScrollLayout.snapToScreen(0);
		} else if (mTab1.getId() == checkedId) {
			if (currIndex == 0) {
				moveFrontBg(mTabImg, zero, one, 0, 0);
			} else if (currIndex == 2) {
				moveFrontBg(mTabImg, two, one, 0, 0);
			} else if (currIndex == 3) {
				moveFrontBg(mTabImg, three, one, 0, 0);
			}
			currIndex = 1;
			mScrollLayout.snapToScreen(1);
		} else if (mTab2.getId() == checkedId) {
			if (currIndex == 0) {
				moveFrontBg(mTabImg, zero, two, 0, 0);
			} else if (currIndex == 1) {
				moveFrontBg(mTabImg, one, two, 0, 0);
			} else if (currIndex == 3) {
				moveFrontBg(mTabImg, three, two, 0, 0);
			}
			currIndex = 2;
			mScrollLayout.snapToScreen(2);
		} else if (mTab3.getId() == checkedId) {
			if (currIndex == 0) {
				moveFrontBg(mTabImg, zero, three, 0, 0);
			} else if (currIndex == 1) {
				moveFrontBg(mTabImg, one, three, 0, 0);
			} else if (currIndex == 2) {
				moveFrontBg(mTabImg, two, three, 0, 0);
			}
			currIndex = 3;
			mScrollLayout.snapToScreen(3);
		}

	}

	/**
	 * 
	 * @函数名称 : moveFrontBg
	 * @功能描述 :
	 * @参数及返回值说明：
	 * @param v
	 * @param startX
	 * @param toX
	 * @param startY
	 * @param toY
	 * 
	 * @修改记录：
	 * @日期：2013-5-3 下午1:59:01 修改人：黄秋
	 * @描述 ：
	 * 
	 */
	public static void moveFrontBg(View v, int startX, int toX, int startY,
			int toY) {
		TranslateAnimation anim = new TranslateAnimation(startX, toX, startY,
				toY);
		anim.setDuration(200);
		anim.setFillAfter(true);
		v.startAnimation(anim);
	}

	@Override
	public void onRefresh() {
		// ((AppContext) getApplicationContext()).finalHttp.get(URL2,
		// new AjaxCallBack<String>() {
		//
		// @Override
		// public void onSuccess(String t) {
		// // TODO Auto-generated method stub
		// super.onSuccess(t);
		// System.out.println("网易新闻图片列表==" + t.toString());
		// mAdapter.notifyDataSetChanged();
		// list2.clear();
		// list2.addAll(Photo_List_Bean.parseJson(t));
		// // mPullDownView.notifyDidRefresh();
		// }
		//
		// @Override
		// public void onFailure(Throwable t, String strMsg) {
		// // TODO Auto-generated method stub
		// super.onFailure(t, strMsg);
		// System.out.println("网易新闻图片列表" + strMsg);
		// Tools.getInstance().showTextToast(MainActivity.this,
		// "网络异常！");
		// // mPullDownView.notifyDidRefresh();
		// }
		// });

	}

	@Override
	public void onMore() {

	}

	@Override
	public void onClick(View v) {

		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		avg_width = findViewById(R.id.layout).getWidth();
		switch (v.getId()) {
		case R.id.tv_title_bar_news:
			moveFrontBg(tv_front, startX, 0, 0, 0);
			startX = 0;
			tv_front.setText("头条");
			if (viewswitcher_tab0.getCurrentView().getId() != findViewById(
					R.id.pull_down_view_tab0).getId()) {
				viewswitcher_tab0.showNext();
			}
			// 准备显示“头条”
			// page = inflater.inflate(R.layout.layout_news_top, null);
			// intent.setClass(TabNewsActivity.this, TabNewsTopActivity.class);
			// page = getLocalActivityManager().startActivity("activity1",
			// intent).getDecorView();
			break;
		case R.id.tv_title_bar_sport:
			moveFrontBg(tv_front, startX, avg_width, 0, 0);
			startX = avg_width;
			tv_front.setText("体育");
			// 准备显示“体育”
			// intent.setClass(TabNewsActivity.this,
			// TabNewsSportActivity.class);
			// page = getLocalActivityManager().startActivity("activity2",
			// intent).getDecorView();
			break;
		case R.id.tv_title_bar_play:
			moveFrontBg(tv_front, startX, avg_width * 2, 0, 0);
			startX = avg_width * 2;
			tv_front.setText("娱乐");
			// 准备显示“娱乐”
			// intent.setClass(TabNewsActivity.this, TabNewsPlayActivity.class);
			// page = getLocalActivityManager().startActivity("activity3",
			// intent).getDecorView();
			break;
		case R.id.tv_title_bar_finance:
			moveFrontBg(tv_front, startX, avg_width * 3, 0, 0);
			startX = avg_width * 3;
			tv_front.setText("财经");
			// 准备显示“财经”
			// intent.setClass(TabNewsActivity.this,
			// TabNewsFinanceActivity.class);
			// page = getLocalActivityManager().startActivity("activity4",
			// intent).getDecorView();
			break;
		case R.id.tv_title_bar_science:
			moveFrontBg(tv_front, startX, avg_width * 4, 0, 0);
			startX = avg_width * 4;
			tv_front.setText("科技");
			// 准备显示“科技”
			// intent.setClass(TabNewsActivity.this,
			// TabNewsScienceActivity.class);
			// page = getLocalActivityManager().startActivity("activity5",
			// intent).getDecorView();
			break;
		case R.id.tv_title_bar_more:
			moveFrontBg(tv_front, startX, avg_width * 5, 0, 0);
			startX = avg_width * 5;
			tv_front.setText("更多");
			if (viewswitcher_tab0.getCurrentView().getId() != findViewById(
					R.id.ll_listView_news_more).getId()) {
				viewswitcher_tab0.showNext();
			}

			// 准备显示“更多”
			// intent.setClass(TabNewsActivity.this, TabNewsMoreActivity.class);
			// page = getLocalActivityManager().startActivity("activity6",
			// intent).getDecorView();
			break;

		default:
			break;
		}
		// 切换

	}

}
